package com.ty.bigevent.exception;

import com.ty.bigevent.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public Result<?> businessExceptionHandler(Exception e) {
        log.error("Exception", e);
        return Result.error(StringUtils.hasLength(e.getMessage())?e.getMessage(): "操作失败");
    }

//    @ExceptionHandler(RuntimeException.class)
//    public Result<?> runtimeExceptionHandler(RuntimeException e) {
//        log.error("RuntimeException", e);
//        return Result.error("系统错误");
//    }
}